package com.box.service.impl;

import com.box.entity.ArticleAndArticleType;
import com.box.mapper.DbArticleAndDbArticleTypeMapper;
import com.box.service.ArticleAndArticleTypeService;
import com.box.utils.StringUtils;
import com.box.utils.search.Page;
import com.box.utils.search.StringUitl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: MyBox
 * @ClassName ArticleAndArticleTypeServiceImpl
 * @description: 文章和文章类型接口实现，基于form表单分页,站内搜索
 * @author: tyf19970214
 * @create: 2020-05-16 20:04
 * @Version 1.0
 **/
@Service
@Transactional
public class ArticleAndArticleTypeServiceImpl implements ArticleAndArticleTypeService {


    @Autowired
    private DbArticleAndDbArticleTypeMapper articleAndDbArticleTypeMapper;



    @Override
    public List<ArticleAndArticleType> getListByMap(Map map) {
        return articleAndDbArticleTypeMapper.getAaaarticleListForPage(map);
    }

    @Override
    public String countArticleAndType() {
        return null;
    }

    /**
     *
     * @param formName
     * @param paramterName
     */
    @Override
    public void getSearchListByWhere(String formName, String paramterName, String keyboard, HttpServletRequest request) throws Exception{
        Page page = new Page(formName);
        String currentPage = request.getParameter(paramterName);
        if(StringUitl.IsNotNull(currentPage)){
            page.setCurrentPage(Integer.parseInt(currentPage));
        }
        //拼装map进行查询
        Map<String,Object> map = new HashMap<>();
        map.put("page",page);
        map.put("artitle",keyboard);
        List list = getListByMap(map);
        //数据展示
        request.setAttribute("ListBySearch",list);
        request.setAttribute("paging",page.getPageStr());

    }
}
